import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error,r2_score

data = pd.read_csv("D:\\learn\\Artificial_Intelligence-master\\artificial_intelligence\\Chapter2\\generated_data.csv")
x = data.loc[:, "x"]
y = data.loc[:, "y"]
x = np.array(x)
x = x.reshape(-1,1)
y = np.array(y)
y = y.reshape(-1,1)

plt.figure()
plt.scatter(x, y)
plt.show()

lr_model = LinearRegression()
lr_model.fit(x,y)

y_predict = lr_model.predict(x)
y_3 = lr_model.predict([[3.5]])

a = lr_model.coef_
b = lr_model.intercept_

MSE = mean_squared_error(y, y_predict)
R2 = r2_score(y, y_predict)
print(MSE, R2)
